package org.ssm.dufy.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.ssm.dufy.service.IUserService;

@Controller
public class UserController {

	@Autowired
	private IUserService userService;

	@RequestMapping(value = "/showname", method = RequestMethod.GET)
	public String showUserName(@RequestParam("uid") int uid, HttpServletRequest request, Model model) {
		System.out.println("showname");
		// User user = userService.getUserById(uid);
		// if(user != null){
		// request.setAttribute("name", user.getUserName());
		// model.addAttribute("mame", user.getUserName());
		// return "showName";
		// }
		// request.setAttribute("error", "没有找到该用户！");
		return "index";

	}

	/**
	 * freemark 测试
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/user", method = { RequestMethod.GET })
	public String getUser(Model model) {
		Map<String, Object> user = new HashMap<>();
		user.put("name", "ssss");
		user.put("email", "22222");
		model.addAttribute("user", user);
		return "userInfo";
	}

	/**
	 * 显示页面视图
	 * 
	 * @param url1
	 * @return
	 */
	@RequestMapping(value = "show/{url1}", method = RequestMethod.GET)
	public String showPage(@PathVariable("url1") String url1) {
		StringBuilder sb = new StringBuilder();
		sb.append("/").append(url1);
		return sb.toString();
	}

	@RequestMapping(value = "show/{url1}/{url2}", method = RequestMethod.GET)
	public String showPage(@PathVariable("url1") String url1, @PathVariable("url2") String url2) {
		StringBuilder sb = new StringBuilder();
		sb.append("/").append(url1).append("/").append(url2);
		return sb.toString();
	}

	@RequestMapping(value = "show/{url1}/{url2}/{url3}", method = RequestMethod.GET)
	public String showPage(@PathVariable("url1") String url1, @PathVariable("url2") String url2, @PathVariable("url3") String url3) {
		StringBuilder sb = new StringBuilder();
		sb.append("/").append(url1).append("/").append(url2).append("/").append(url3);
		return sb.toString();
	}

}